/* Includes ------------------------------------------------------------------*/
#include "wb32l003.h"
#include <stdio.h>
#include "MACRO.H"
#include "VALUE_SET.H"
#include "IO_SETUP.H"


/****************************************************************************************************************************************/
void MAINCLK_FREQ_HSI_24M(void)
{RCC_HSIConfig(24000000, ENABLE);
 /* wait HSI clock ready */
 while ((RCC->HSICR & RCC_HSICR_HSIRDY) == RESET);
 RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
 /* Wait till clock switch is ready */
 while ((RCC->SYSCLKSEL & RCC_SYSCLKSEL_CLKSW) != RCC_SYSCLKSource_HSI);
 SystemCoreClock = 24000000;
 RCC_AHBCLKConfig(RCC_AHBCLKDiv1);
 RCC_APBCLKConfig(RCC_APBCLKDiv1);}
/****************************************************************************************************************************************/
void MAINCLK_FREQ_HSI_16M(void)
{RCC_HSIConfig(16000000, ENABLE);
 /* wait HSI clock ready */
 while ((RCC->HSICR & RCC_HSICR_HSIRDY) == RESET);
 RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
 /* Wait till clock switch is ready */
 while ((RCC->SYSCLKSEL & RCC_SYSCLKSEL_CLKSW) != RCC_SYSCLKSource_HSI);
 SystemCoreClock = 24000000;
 RCC_AHBCLKConfig(RCC_AHBCLKDiv1);
 RCC_APBCLKConfig(RCC_APBCLKDiv1);}
/****************************************************************************************************************************************/
void MAINCLK_FREQ_HSI_8M(void)
{RCC_HSIConfig(8000000, ENABLE);
 /* wait HSI clock ready */
 while ((RCC->HSICR & RCC_HSICR_HSIRDY) == RESET);
 RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
 /* Wait till clock switch is ready */
 while ((RCC->SYSCLKSEL & RCC_SYSCLKSEL_CLKSW) != RCC_SYSCLKSource_HSI);
 SystemCoreClock = 24000000;
 RCC_AHBCLKConfig(RCC_AHBCLKDiv1);
 RCC_APBCLKConfig(RCC_APBCLKDiv1);}
/****************************************************************************************************************************************/
void MAINCLK_FREQ_HSI_4M(void)
{RCC_HSIConfig(4000000, ENABLE);
 /* wait HSI clock ready */
 while ((RCC->HSICR & RCC_HSICR_HSIRDY) == RESET);
 RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
 /* Wait till clock switch is ready */
 while ((RCC->SYSCLKSEL & RCC_SYSCLKSEL_CLKSW) != RCC_SYSCLKSource_HSI);
 SystemCoreClock = 24000000;
 RCC_AHBCLKConfig(RCC_AHBCLKDiv1);
 RCC_APBCLKConfig(RCC_APBCLKDiv1);}
/****************************************************************************************************************************************/
void SetSysClockToLSI_32K(void)
{RCC_LSIConfig(LSI_VALUE_32K, RCC_LSI_STARTUP_64CYCLE, ENABLE);
 /* wait LSI clock ready */
 while ((RCC->LSICR & RCC_LSICR_LSIRDY) == RESET);
 RCC_SYSCLKConfig(RCC_SYSCLKSource_LSI);
 /* Wait till clock switch is ready */
 while ((RCC->SYSCLKSEL & RCC_SYSCLKSEL_CLKSW) != RCC_SYSCLKSource_LSI);
 SystemCoreClock = LSI_VALUE_32K;
 RCC_AHBCLKConfig(RCC_AHBCLKDiv1);
 RCC_APBCLKConfig(RCC_APBCLKDiv1);}
